package net.zjitc.boot_demo.service.impl;


import net.zjitc.boot_demo.mapper.CategoryMapper;
import net.zjitc.boot_demo.pojo.Category;
import net.zjitc.boot_demo.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CategoryServiceImpl implements CategoryService {

    @Autowired
    private CategoryMapper categoryMapper;

    @Override
    public List<Category> findAll() {
        List<Category> list= categoryMapper.findAll();
        for (int i = 0; i < list.size(); i++) {
            int index = 0;
            if (list.get(i).getPid() == 0) {
                continue;
            }else {
                int pid = list.get(i).getPid() - 1;
                String name = list.get(pid).getName();
                list.get(i).setPname(name);
            }
        }
        return list;
    }
}
